package com.sptpc.myloginui;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    Button btn;
    EditText passUser;
    EditText passWord;
    String inputUser;
    String inputPassword;

    public static final String myLoginuser = "1812212246";
    public static final String myLoginpassword = "admin";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);

        btn = (Button)findViewById(R.id.login);
        passUser = (EditText)findViewById(R.id.text_user);
        passWord = (EditText)findViewById(R.id.text_password);

        passUser.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }
            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }
            @Override
            public void afterTextChanged(Editable editable) {
                inputUser = passUser.getText().toString();
            }
        });

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                inputUser = passUser.getText().toString();
                inputPassword = passWord.getText().toString();
                if (inputUser.equals(myLoginuser) && inputPassword.equals(myLoginpassword)){
                        Toast.makeText(MainActivity.this,"账号正确，登录成功",Toast.LENGTH_SHORT).show();
                        Intent intent = new Intent(MainActivity.this,QQmain.class);
                        startActivity(intent);
                    }else {
                        Toast.makeText(MainActivity.this,"账号或密码错误，登录失败",Toast.LENGTH_SHORT).show();
                    }
                }
             });

        TextView tv_Create = (TextView)findViewById(R.id.createLoginAccount);
        tv_Create.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this,CreateNewAccount.class);
                startActivity(intent);
            }
        });
    }

}

